Skip to content

perf: Migrate to Flashlist in MoneyRequestReportTransactionList#91422

Open
TMisiukiewicz wants to merge 94 commits into
Expensify:mainfrom
callstack-internal:perf/virtualised-report-list
Open

perf: Migrate to Flashlist in MoneyRequestReportTransactionList#91422
TMisiukiewicz wants to merge 94 commits into
Expensify:mainfrom
callstack-internal:perf/virtualised-report-list

Conversation

@TMisiukiewicz

@TMisiukiewicz TMisiukiewicz commented May 22, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Problem
On heavy money-request reports the RHP list was effectively non-virtualised. The inner transactions section was rendered via plain .map() inside the parent FlatList's ListHeaderComponent, which renders eagerly. Every transaction row mounted synchronously when the report opened, pushing report open time to ~20–30s for a report with 1600 expenses and producing a noticeable jank window on every navigation.

Solution

  1. Unified list — merged the inner transactions section and the outer report-actions section into a single virtualised list. A discriminated-union UnifiedListItem (section-header | transaction | transactions-footer | report-action) flows through one renderItem dispatcher, so transactions and chat messages now share the same recycler window instead of one being eagerly rendered inside the other's header.

  2. FlashList — migrated the list from react-native's FlatList (FlatListWithScrollKey). initialScrollIndex replaces the FlatList-specific useFlatListScrollKey wrapper

  3. Controller + sub-componentMoneyRequestReportTransactionList continues to own the transaction-domain state (sort, group-by, selection, columns, totals, etc.) and exposes it to the parent via a render-prop controller. The parent renders a small MoneyRequestReportUnifiedList sub-component that assembles the FlashList from controller data plus the report-actions list

Fixed Issues

$ #91425
PROPOSAL:

Tests

Before testing: npm run i-standalone as this PR contains patch to the FlashList

  1. Go to Spend tab
  2. Go to Reports tab
  3. Open Report with a couple of expenses - where list is not scrollable
  4. Verify everything is displayed correctly
  5. Open Report with a lot of expenses in multiple categories
  6. Verify report opens correctly
  7. Select a single report and verify it selects correctly
  8. Select all reports from a category using category header and verify they are all selected (even if they are out of the viewport)
  9. Select all reports from all categories using top table header and verify all reports in a list get selected
  10. Send a message on the report and verify you are scrolled to the bottom of the list
  11. Web only: Narrow down the viewport horizontally and verify the table is scrollable horizontally
  12. Send a couple of messages on the chat
  13. Verify that messages are not scrolled horizontally together with the table
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
ios.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 94.81% <ø> (ø)
...ansactionItemRow/DeferredTransactionItemRowRBR.tsx 100.00% <100.00%> (ø)
...ents/TransactionItemRow/TransactionItemRowWide.tsx 99.14% <100.00%> (+<0.01%) ⬆️
src/components/TransactionItemRow/index.tsx 83.60% <100.00%> (+0.55%) ⬆️
src/hooks/useReportActionsScroll.ts 98.23% <100.00%> (ø)
src/hooks/useScrollToEndOnNewMessageReceived.ts 94.11% <100.00%> (ø)
...stReportView/MoneyRequestReportTransactionItem.tsx 0.00% <0.00%> (ø)
...ts/TransactionItemRow/TransactionItemRowNarrow.tsx 0.00% <0.00%> (ø)
...ew/MoneyRequestReportTransactionLongPressModal.tsx 0.00% <0.00%> (ø)
...equestReportView/MoneyRequestReportActionsList.tsx 58.72% <36.17%> (-5.18%) ⬇️
... and 3 more
... and 26 files with indirect coverage changes

@TMisiukiewicz TMisiukiewicz changed the title perf: virtualise transaction list in report screen perf: Migrate to Flashlist in MoneyRequestReportTransactionList May 26, 2026
@TMisiukiewicz TMisiukiewicz marked this pull request as ready for review May 26, 2026 07:20
@TMisiukiewicz TMisiukiewicz requested review from a team as code owners May 26, 2026 07:20
@melvin-bot melvin-bot Bot requested review from aimane-chnaif and joekaufmanexpensify and removed request for a team and joekaufmanexpensify May 26, 2026 07:20
@melvin-bot

melvin-bot Bot commented May 26, 2026

Copy link
Copy Markdown

@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Comment thread src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Outdated
Comment thread src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b5c9bef51

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx Outdated
@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

@mountiny can you run another adhoc build here? @aimane-chnaif I think I resolved the remaining bugs, could you check again?

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

…rt-list

# Conflicts:
#	src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx
Comment thread src/components/Table/TableBody.tsx Outdated
@MelvinBot

Copy link
Copy Markdown
Contributor

Regression review

I reviewed the diff focusing on (a) blast radius outside the money-request report view and (b) behavioral regressions in the migrated list. Three likely regressions, all inside MoneyRequestReportView — the shared-component and deleted-file changes are clean.

🔴 Confirmed regressions

1. Wide-table horizontal scroll position is no longer restored
On wide tables, the horizontal offset is lost on any transaction-data change (sort, new transaction, RBR reorder). main restored it via a useLayoutEffect keyed on the transactions; the new ExternalScrollFlashListTable.tsx:189-212 renders the horizontal ScrollView with no ref, no onScroll capture, and no restoration effect. The controller still computes horizontalScrollRestorationKey and documents it as "used to restore the previous offset" (MoneyRequestReportTransactionList.tsx:1088), but nothing consumes it → the table snaps back to the left column. (High confidence)

2. New/sent-message autoscroll still uses estimated scrollToEnd on large lists
The pill and send path were moved to indexed scrollToBottom, but useScrollToEndOnNewMessageReceived is still wired to reportScrollManager.scrollToEnd (MoneyRequestReportActionsList.tsx:497-507 → hook useScrollToEndOnNewMessageReceived.ts:81). So when another participant's message arrives while the user is at the bottom of a large transaction+chat report, autoscroll can land on the blank estimated end — the exact failure mode the indexed jump was added to avoid (author's own comment, L104-L106). (High confidence — this is the codex P2 flag, validated.)

3. Cold-open deep-link to a report action may not anchor
initialScrollIndex is a mount-only hint; if the linked action isn't in visibleReportActions at first mount, MoneyRequestReportUnifiedList.tsx:197-198 yields -1/undefined and there's no post-mount re-anchoring (the removed FlatListWithScrollKey re-derived the index from the reportActionID key across data growth). maintainVisibleContentPosition (default-on) keeps things stable once anchored, so the gap is specifically the cold deep-link open before the linked action paginates in. (Medium confidence — codex P1, partially validated; worth a quick manual test of a linked-message deeplink into a long report.)

Bot-flagged concerns I checked and refuted (no change needed)
  • Unread-marker viewability offset (codex P1): refutedonViewableItemsChangedAdjusted already subtracts reportActionIndexOffset before forwarding to the unread hook (MoneyRequestReportUnifiedList.tsx:172-181).
  • Loading skeleton lost when only actions are loading (codex P2/P3): refuted — skeleton was moved to ListFooterComponent for the inlined case and gated on reportActionItems.length === 0 (L129, L259-260).
  • Selection across viewport / recycling: fine — selection is prop-driven per render.
Shared-component & deleted-file changes — no regression outside the report view
  • Deleted FlatListWithScrollKey / useFlatListScrollKey / getInitialPaginationSize / getInitialNumReportActionsToRender: zero remaining references anywhere in src/. The normal chat (ReportActionsList) was already on InvertedFlashList and never depended on them. No build break.
  • useReportActionsScroll / useScrollToEndOnNewMessageReceived: pure constant relocation — AUTOSCROLL_TO_TOP_THRESHOLD moved to CONST.REPORT.ACTIONS with the identical value (250), signatures unchanged. Other consumer (ReportActionsList) unaffected.
  • TransactionItemRow (+ types.ts): purely additive optional prop shouldSkipDeferRBR (default false reproduces the old always-deferred behavior). Only MoneyRequestReportTransactionItem passes it; Search/UnreportedExpense/TransactionMerge/TransactionDuplicate callers are unchanged.
  • TableBody.tsx flexGrow1flex1 (aimane's earlier question): confirmed no-op for current consumers — the changed branch only runs in the empty state with a ListEmptyComponent, and no shared-@components/Table consumer supplies one.
  • CONST/index.ts: single additive constant.

Confirmed with code evidence; #1 and #2 are straightforward to reproduce on a large report. Reply with @MelvinBot <feedback> to dig deeper into any of these.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

Blockers

  • TableBody.tsx change (flexGrow1 → flex1) is no longer necessary

  • useScrollToEndOnNewMessageReceived still uses scrollToEnd

The PR added scrollToBottom and moved every current-user-message path onto it, explicitly because the PR itself comments that scrollToEnd leaves the bottom blank on large lists.
But useScrollToEndOnNewMessageReceived is still fed the raw reportScrollManager.scrollToEnd.
That hook fires when a message arrives from any account while the user is near the bottom — the same "hundreds of transactions + chat" scenario the PR sized the fix for.
Route it through scrollToBottom too.

Repro: Receive the message coming from another account/device (not current user).

New concerns introduced by the ExternalScrollFlashListTable architecture

C1. LayoutManager is not initialized swallow is string-matched

ExternalScrollFlashListTable.tsx:108-111:

} catch (error) {
    if (!(error instanceof Error) || !error.message.includes('LayoutManager is not initialized')) {
        throw error;
    }
}

The back-navigation crash fix (commit b5dc428eb74) works by ignoring specifically-worded errors from FlashList. If the upstream ever rewords that message — e.g. LayoutManager not initialized, or moves it behind a typed error — the catch stops matching and the crash resurfaces. Either sync the message into a shared constant with FlashList (given you already patch it) or catch a specific error class.

C2. Nested FlashList viewportHeight starts at 0 on first paint

MoneyRequestReportUnifiedList.tsx:143: const [viewportHeight, setViewportHeight] = useState(0);. Before the outer FlashList's onLayout fires, viewportHeight is 0, which flows into ExternalScrollFlashListTable's overrideWindowSize={{width: contentWidth, height: 0}}. FlashList windows against a zero-height viewport — nothing to render, drawDistance clamps to zero effective coverage.

Usually harmless because onLayout fires on the next frame, but on cold navigation into a wide-table report you can catch a frame where the transactions area is blank / renders only the estimated top row. Consider seeding with windowHeight from useWindowDimensions on first paint.

Repro: cold-navigate to a wide-table report and screenshot the first frame after the navigation transition.

C3. scrollOffsetStore not reset when isHorizontalTable transitions on the same report

MoneyRequestReportUnifiedList.tsx:150-154 resets the offset store on report.reportID change, but not when isHorizontalTable toggles. If the user is in inline mode, scrolls the list, then drags the browser narrow enough for isHorizontalTable to flip:

  • The store still holds 0 because handleScroll only writes when isHorizontalTable === true.
  • The outer FlashList's actual contentOffset.y is at whatever the user scrolled to.
  • The nested ExternalScrollDriver.emit() runs with the stale 0, so the nested table paints the top rows even though the outer list is scrolled hundreds of pixels down.

Correction happens on the next scroll event, but the first frame after the transition shows top-of-table content. Reset the store on any isHorizontalTable change (or better, always feed it in handleScroll and just ignore consumers when inline).

C4. Deep-link (initialScrollIndex) into a transaction row is silently unsupported

MoneyRequestReportUnifiedList.tsx:197-198 computes linkedActionLocalIndex only against visibleReportActions. If a deep link ever targets a transaction row (indirect flow — e.g. some Onyx-side redirect turns a reportActionID into a transactionID in the URL), the finder returns -1, initialScrollIndex = undefined, and the wide-table case never scrolls anywhere near it. Not a regression (the original code was the same) but the wide-table hop through overrideWindowSize makes this actively harder to fix later — worth noting.

C5. Nested FlashList shares the getItemType bug

Still H3-style: unifiedListItemType returns 'section-header' / 'transaction' / 'transactions-footer' / 'report-action' for the outer list, and the same function is re-used as the nested table's getItemType. Different transaction rows (grouped vs regular, with-receipt vs without) all share the 'transaction' bucket, so recycling can shuffle rows with very different DOM subtrees. Same chat-list migration lesson — either bucket by transaction.hasReceipt / columns.length or narrow the type down.

C6. Neither the outer nor the nested FlashList sets extraData

Same as H2 in prior rounds. Selection toggles, column visibility changes, and highlight-set changes don't touch data identity for the transactions section. React Compiler may catch some of it, but the safety net (extraData=[selectedTransactionIDs, columnsToShow, highlightedTransactionIDs, currentGroupBy]) is one line and eliminates the class of bugs. Applies to both the outer and the nested <FlashList>.

C7. handleScroll / handleLayout / dispatchRenderItem / nested renderItem are all inline closures

New function identity every render:

  • MoneyRequestReportUnifiedList.tsx:156, 164, 183
  • ExternalScrollFlashListTable.tsx:199renderItem={({item, index}) => renderItem(item, index, {isFirst, isLast})}
  • Inline style={{...}} object on ExternalScrollFlashListTable.tsx:209

FlashList's internal optimizations (memoized cell wrappers) rely on stable identity to skip work. All of these fire every parent render regardless of what changed. memo(MoneyRequestReportUnifiedList) on line 266 also bails on every render because controller is a fresh object literal — same R13 code smell as before.

C8. MoneyRequestReportFlashList shim is now dead code

MoneyRequestReportUnifiedList.tsx:46-64 exists specifically to launder FlatListRefType into a FlashListProps.ref. But FlatListRefType now lives at @components/FlashList/types (per line 2) and is presumably already the correct type. The wrapper is a bare {...props} spread — no runtime purpose. Either delete or explain the safety it still buys.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

Bug when resize window
Screenshot 2026-07-10 at 9 37 36 am

this branch:

Screen.Recording.2026-07-10.at.9.17.28.AM.mov

production:

Screen.Recording.2026-07-10.at.9.17.52.AM.mov

@aimane-chnaif

aimane-chnaif commented Jul 10, 2026

Copy link
Copy Markdown
Contributor
  1. Send a message on the report and verify you are scrolled to the bottom of the list

Sometimes this doesn't work. Not consistent.
I have ever reproduced in staging but not found reliable repro step.
So I'd say this is not blocker.

Screen.Recording.2026-07-10.at.10.08.24.AM.mov

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author
  1. Wide-table horizontal scroll position is no longer restored

not valid - ScrollView does not re-position unless it's re-mounted

  1. New/sent-message autoscroll still uses estimated scrollToEnd on large lists

fixed in 71f12e8

  1. Cold-open deep-link to a report action may not anchor

fixed in 1814a1ee60a8a7ecee5693e468b43eee14713484

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

C1. LayoutManager is not initialized swallow is string-matched

fixed in 970d609

C2. Nested FlashList viewportHeight starts at 0 on first paint

fixed in 335748a

C3. scrollOffsetStore not reset when isHorizontalTable transitions on the same report

fixed in 335748a

C4. Deep-link (initialScrollIndex) into a transaction row is silently unsupported

Nothing in the codebase ever writes a transactionID into that param. I don't think we should write code for a flow that does not exist

C5. Nested FlashList shares the getItemType bug

not valid

C6. Neither the outer nor the nested FlashList sets extraData

I don't think we have any bug introduced by lack of extraData so I am not in favor of adding this unless necessary

C7. handleScroll / handleLayout / dispatchRenderItem / nested renderItem are all inline closures

React Compiler handles this

C8. MoneyRequestReportFlashList shim is now dead code

not valid

I'll check the resize and send message bugs soon

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

@aimane-chnaif I can't reproduce the resize bug - can you verify again? Might be accidentally fixed by one of my recent commits 😅

@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

also couldn't reproduce the issue with the scroll after msg

@aimane-chnaif

Copy link
Copy Markdown
Contributor

After resize window, blank screen briefly appears. (00:04s)

Screenshot 2026-07-10 at 3 46 57 pm

Also when scroll fast (00:42s)

Screenshot 2026-07-10 at 3 47 13 pm
Screen.Recording.2026-07-10.at.3.45.00.pm.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants